package com.wxapp.admin.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.admin.api.pojo.vm.role.PRoleDetailVm;
import com.wxapp.admin.api.pojo.vm.role.PRolePageVm;
import com.wxapp.admin.api.pojo.vo.role.QRolePageVo;
import com.wxapp.admin.api.pojo.vo.role.QRoleSaveVo;
import com.wxapp.admin.api.pojo.vo.role.QRoleUpdateVo;
import com.wxapp.admin.service.service.RoleService;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 角色管理
 * @Datetime 2022/8/3 14:58
 * @Modified By
 */
@RestController
@RequestMapping("role")
@Tag(name = "角色管理")
@RequiredArgsConstructor
public class RoleController extends IBaseController {
   private final RoleService roleService;

    @PostMapping("/save")
    @Operation(summary ="保存角色信息")
    public ResultVm<String> saveRole(@Schema(hidden = true) @User UserVo userVo, @RequestBody QRoleSaveVo qRoleSaveVo) {
        return roleService.saveRole(userVo, qRoleSaveVo);
    }

    @PutMapping("/update")
    @Operation(summary ="更新角色信息")
    public ResultVm<String> updateRole(@Schema(hidden = true) @User UserVo userVo, @RequestBody QRoleUpdateVo qSaveVo) {
        return roleService.updateRole(userVo, qSaveVo);
    }

    @GetMapping("/detail")
    @Operation(summary ="得到角色详情")
    public ResultVm<PRoleDetailVm> detailRole(@RequestParam String id) {
        return roleService.detailRole(id);
    }

    @GetMapping("/detailByUser")
    @Operation(summary ="得到角色详情")
    public ResultVm<List<PRoleDetailVm>> detailByUser(@Schema(hidden = true) @User UserVo userVo, @RequestParam(value = "userId", required = false) String userId) {
        return roleService.detailByUser(userVo, userId);
    }

    @PostMapping("/page")
    @Operation(summary ="更新角色信息")
    public ResultVm<Page<PRolePageVm>> pageRole(@RequestBody QRolePageVo qSaveVo) {
        return roleService.pageRole(qSaveVo);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary ="删除角色")
    public ResultVm<String> deleteRole(@PathVariable String id) {
        return roleService.deleteRole(id);
    }
}
